using System;
using System.Collections.Generic;
using System.Text;
using Rapier.Kodachi.Shared;
using System.Drawing;
using System.Runtime.InteropServices;

namespace Rapier.Kodachi.SystemCommands.Actions
{
    public class Restart : Action
    {
        [DllImport("user32.dll")]
        public static extern int ExitWindowsEx(int uFlags, int dwReason);

       private Bitmap restartImage; 

        #region Constructor
        public Restart(Plugin plugin)
            : base(plugin, "Rapier.Kodachi.SystemCommands.Restart", "Restart Windows", "Close all apps and restart windows.")
        {
            restartImage = Rapier.Kodachi.SystemCommands.Properties.Resources.Restart.ToBitmap();
            this.IndirectItemUse = IndirectItemUse.None;
            GetImage = delegate()
            {
               return restartImage;
            };
        }
        #endregion

        #region Action Members
        public override void Execute(Item[] directItems, Item[] indirectItems)
        {
            ExitWindowsEx(2, 0);
        }

        public override bool IsValidIndirect(Item indirectItem)
        {
            return false;
        }

        public override bool IsValidDirect(Item directItem)
        {
            return directItem.Properties.ContainsKey("SystemCommand") && (bool)(directItem.Properties["SystemCommand"]) == true;
        }
        #endregion
    }
}
